<template>
  <a-layout id="components-layout-demo-custom-trigger">
    <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
      <div class="logo">
        欢迎你，{{ username }}
        <leftmenu :menu_number="4"></leftmenu>
      </div>
    </a-layout-sider>

        <a-layout>
<headmenu></headmenu>

    <a-layout-content
      :style="{
        margin: '24px 16px',
        padding: '24px',
        background: '#fff',
        minHeight: '500px',
      }"
    >
      <h2>审批工单</h2>
      <a-breadcrumb>
        <a-breadcrumb-item>我审批的工单</a-breadcrumb-item>
        <!-- <a-breadcrumb-item><a href="">Application Center</a></a-breadcrumb-item> -->
        <a-breadcrumb-item><a href="/task">我审批的工单</a></a-breadcrumb-item>
        <a-breadcrumb-item>审批工单</a-breadcrumb-item>
      </a-breadcrumb>

      <h2>{{ task_list.name }}</h2>
      <b>申请人：{{ task_list.username }}</b>
      <div v-for="(value, key) in task_list.work_data" :key="key">
        <div v-if="key == 'img'">img:<img :src="value" alt="" style="width: 80px"></div>
        <p v-else>{{ key }}:{{ value }}</p>
      </div>
      <p>审批意见<input type="text" v-model="refuse_text" /></p>

      <a-button type="primary" @click="consent"> 同意 </a-button>

      <a-button type="primary" @click="refuse"> 拒绝 </a-button>
    </a-layout-content>
  </a-layout>
          </a-layout>
</template>


<script>
import { get_one_task, put_task } from "./axios_http/api";

// 导入组件
import leftmenu from "./leftmenu.vue";
import headmenu from './headmenu.vue';
export default {
  data() {
    return {
      task_id: this.$route.query.task_id,
      refuse_text: "",
      collapsed: false,
      username: localStorage.getItem("username"),
      task_list: [],
    };
  },
  methods: {
    refuse() {
      let data = {
        work_id: this.task_list.id,
        type: "拒绝",
        task_id: this.task_id,
        refuse_: this.refuse_text,
        username: this.task_list.username
      }
      console.log(data)
      put_task(data).then((resp) => {
        console.log(resp);
      });
    },
    consent() {
      put_task({
        work_id: this.task_list.id,
        type: "同意",
        task_id: this.task_id,
        refuse_: this.refuse_text,
        username: this.task_list.username
      }).then((resp) => {
        console.log(resp);
      });
    },
  },
  components: {
    leftmenu: leftmenu,
        headmenu:headmenu,
  },
  created() {
    get_one_task(this.task_id).then((resp) => {
      this.task_list = resp.data;
      console.log(this.task_list);
    });
  },
};
</script>